package com.gzp.controller;

import java.util.HashMap;
import java.util.Map;

import javax.jms.Topic;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/topic/")
public class TopicController {

	@Autowired
	private JmsMessagingTemplate jmsMessagingTemplate;
	@Autowired
	private Topic topic;

	@GetMapping("produceMsg")
	public Map<String, Object> produceMsg(String message) {
		Map<String, Object> result = new HashMap<String, Object>();
		jmsMessagingTemplate.convertAndSend(topic, message);
		result.put("code", 200);
		result.put("msg", "“" + message + "”消息发送成功！");
		return result;
	}
}
